//functions for list question action.

$(document).ready(function() {
	//$('#tblQuestion').dataTable();
	$('#tblQuestion_info').css('float', 'left');
	$('#tblQuestion_paginate').css('float', 'right');
	//$('#tblQuestion').dataTable().fnSetColumnVis( 0, false);
	
	$('#tblQuestion tbody tr').click(function (){
		var rows = $('#tblQuestion tbody tr.selected_row');
		if(rows.length != 0){
			rows.removeClass('selected_row');
		}
		$(this).addClass('selected_row');
		$('#btnShowQuestion').removeAttr('disabled');
		$('#btnAddQuestion').removeAttr('disabled');
		$('#btnDeleteQuestion').removeAttr('disabled');
		$('#btnEditQuestion').removeAttr('disabled');
	});
	
	$('#btnDeleteQuestion').click(function(){
		var rows = $('#tblQuestion tbody tr.selected_row');
		if(rows.length !== 0){
			if(confirm("Do you want to delete this question?")){
				$.ajax({
					url: '/eonline/questions/delete',
					type: 'post',
					data: {
						'id': rows[0].cells[0].innerHTML, 
					},
					success: function(result){
						if(result < 0){
							alert("Deleting question is not succefull, please check again.")
						}
						else if(result == 0){
							alert("Deleting question is not succefull, please check again.")
						}
						else{
							$('#tblQuestion').dataTable().fnDeleteRow(rows[0]);
						}
		    		},
		    		error: function(e){
		    			alert("Error: There was an error while sending request to server.");
		    		}
    			});
			}
		}
		else{
			alert("Please choose a row to delete!")
		}
	});

	$('#btnEditQuestion').click(function(){

	});
	
});

//end functions for list question action.


$(document).ready(function() {
	$('#idQT').change(function(){
		alert(1);
		if($('#idQT').val()==1){
			$('#idAudioDiv').show();
		}
		else{
			$('#idAudioDiv').hide();
			$('#idAudioField').attr({value: ''});
		}
	});
	
 });

function repare_submit(divId){
	var editor_data = CKEDITOR.instances[divId].getData();
	var QuestionContents = document.getElementById(divId);
	QuestionContents.value = editor_data;
	return false;
}